/**
*   getParametersNames test (servlet)
*   4/6/2012
*/

package org.buptjunjun.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class ParamNames extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                  	 HttpServletResponse response) 
					 throws IOException ,ServletException
	{
		response.setContentType("text/html");
		
		PrintWriter out = response.getWriter();
		out.println("<HTML><BODY>");
		//get the names of all parameters;
		Enumeration paramNames = request.getParameterNames();			  
		//print the name of each of the Params;
		while(paramNames.hasMoreElements())
		{
			//get the name of each param
			String paramName = (String)paramNames.nextElement();   
			//get the param values of certain param
			String [] paramValues = request.getParameterValues(paramName);
			if(paramValues != null)
			{
			   out.println(paramName+":");
			   for(int i = 0; i < paramValues.length; i++)
			   {
				   out.print(paramValues[i]+",");
			   }
			   out.println("| <br>");
			}
		}
		
		out.println("</BODY></HTML>");
	
	}
	
    public void doPost(HttpServletRequest request,
	              HttpServletResponse response)
				  throws IOException, ServletException
	{
	    doGet(request,response);
	}

}